<?php
//开启session
// $id = !empty($_GET['id'])?$_GET['id']:'';
if (!empty($_POST)) {

    $id = $_GET['id'];
    // if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
    // 查询数据库


 $data = getSelectByOne('admin',"id=$id");

  // echo  $sql = "select * from  `admin` where `id`={$id} ";
  //   die;// 查询到的结果存起来
  //   $result = mysqli_query($link, $sql);


  //   $data = mysqli_fetch_assoc($result);
    // 获取影响的行数
    // $_rows=mysqli_affected_rows($link);
    // 获取新的输入的密码
      $new_p = md5($_POST['new_p']);


    if (md5($_POST['password'])==$data['password'] && $_POST['new_p']==$_POST['new_p1']){
    //编写插入语句
     $sq = "update `admin` set `password` = '{$new_p}' where `id` ={$id}";
    
    //编写执行语句
    mysqli_query($link, $sq);
    //mysqli_affected_rows($link)语句可以检测语句是否执行成功
    $_rows = mysqli_affected_rows($link);
    //如果$_rows>0说明成功
    if ($_rows > 0) {
        echo '<script> alert ("密码修改成功");location.href="index.php?c=admin&a=list&admin=1";</script>';
        die;
    } else {
        echo '<script> alert ("密码修改失败");history.go(-1);</script>';
        die;
    }
}
}
// print_r($data);die;
//链接语句
include VIEW_PATH . $admin . 'layout.html';
?>

<?php 